<?php

namespace App\Console\Commands;

use App\Models\YeepayBank;
use Illuminate\Console\Command;

class YeepayBankInitCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'bank:yeepay';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化易宝实名认证支持的银行列表';

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // 数据来源【易宝支付总行编码】,只显示其中部分银行
        // https://open.yeepay.com/docs/v2/products/ptssfk/others/5f3cef4420289f001ba82523/5f3cf255f56e9d001bbc58c9/index.html
        $rawData = [
            'ICBC' => '中国工商银行',
            'CEB' => '中国光大银行',
            'CCB' => '中国建设银行',
            'CMBC' => '中国民生银行',
            'ABC' => '中国农业银行',
            'BOC' => '中国银行',
            'PSBC' => '中国邮政储蓄银行',
            'ECITIC' => '中信银行',
            'BOCO' => '交通银行',
            'BCCB' => '北京银行',
            'CGB' => '广发银行',
            'HZYH' => '杭州银行',
            'NJYH' => '南京银行',
            'NBYH' => '宁波银行',
            'SDB' => '平安银行(深圳发展银行)',
            'QDYH' => '青岛银行',
            'XMYH' => '厦门银行',
            'SHYH' => '上海银行',
            'SCBANK' => '四川银行',
            'SZYH' => '苏州银行',
            'TJYH' => '天津银行',
            'XAYH' => '西安银行',
            'CIB' => '兴业银行',
            'CMBCHINA' => '招商银行',
            'CZ' => '浙商银行',
        ];
        YeepayBank::truncate();
        foreach ($rawData as $code => $name) {
            $bank = new YeepayBank();
            $bank->code = $code;
            $bank->name = $name;
            $bank->save();
            $this->output->write('.');
        }

        return Command::SUCCESS;
    }
}
